package com.team4.muchentuchen;


import com.team4.general.OSMView;
import org.mapsforge.android.maps.GeoPoint;
import org.mapsforge.android.maps.MapActivity;
import org.mapsforge.android.maps.MapController;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class Map extends MapActivity implements LocationListener{
	
	
	MapController mControl;
	GeoPoint GeoP;
	OSMView mapView;
	double latitude = 32.06667;
	double longitude = 34.8;
	
	
	public void onCreate(Bundle savedInstanceState) 	
	{		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.map);
		mapView = (OSMView) findViewById(R.id.OpenStreetMap);
		mControl = mapView.getController(); 
	    GeoP = new GeoPoint((int) (latitude*1E6),(int) (longitude*1E6)); //Convert long lat into microDegs
	    mControl.setCenter(GeoP);
	    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 100, this);
	    //This is only if we want to update via network provider
	    //lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 100, this);
	}


	public void onLocationChanged(Location location) {
		if (location != null) {
			double lat = location.getLatitude();
			double lng = location.getLongitude();
			GeoPoint GP = new GeoPoint((int) (lat*1E6),(int) (lng*1E6));
			mControl.setCenter(GP);
		}
	}


	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}


	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}


	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}


}
